const Router = require(`@koa/router`)
const router =new  Router()
const { verify } = require('../utils/jwt.js')
const { findNoteListByType } = require('../controllers/index.js')

router.get('/findNoteListByType', verify(), async (ctx) => {
    const {note_type} = ctx.request.query
    // console.log(note_type);
    try{
        const res = await findNoteListByType(note_type, ctx.userId)
        // console.log(res);
        if(res.length === 0){
            ctx.body = {
                code: '0',
                msg: '没有该类型的日记',
                data: []
            }
        } else {
            ctx.body = {
                code: '1',
                msg: '查询成功',
                data: res
            }
        }
    } catch (error){
        ctx.body = {
            code: '-1',
            msg: '查询失败',
            data: error
        }
    }
})

module.exports = router
